using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace DatabaseGroup.WinForms.UserControls
{
    /// <summary>
    /// Displays a thin etched line
    /// </summary>
    public partial class EtchedLine : UserControl
    {
        private Color _darkColor = SystemColors.ControlDark;
        private Color _lightColor = SystemColors.ControlLightLight;
        
        /// <summary>
        /// Initializes a new instance of the EtchedLine class
        /// </summary>
        public EtchedLine()
        {
            InitializeComponent();

            // Avoid receiving the focus.
            SetStyle(ControlStyles.Selectable, false);
        }

        /// <summary>
        /// Gets or sets the color used for the dark part of the line
        /// </summary>
        [Category("Appearance")]
        Color DarkColor
        {

            get { return _darkColor; }

            set
            {
                _darkColor = value;
                Refresh();
            }
        }

        /// <summary>
        /// Gets or sets the color used for the light part of the line
        /// </summary>
        [Category("Appearance")]
        Color LightColor
        {
            get { return _lightColor; }

            set
            {
                _lightColor = value;
                Refresh();
            }
        }

        /// <summary>
        /// Fires the Paint event and redraws the line
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Brush lightBrush = new SolidBrush(_lightColor);
            Brush darkBrush = new SolidBrush(_darkColor);
            Pen lightPen = new Pen(lightBrush, 1);
            Pen darkPen = new Pen(darkBrush, 1);

            e.Graphics.DrawLine(darkPen, 0, 0, Width, 0);
            e.Graphics.DrawLine(lightPen, 0, 1, Width, 1);
        }

        /// <summary>
        /// Fires the Resize event and then invalidates the control
        /// to trigger it to be repainted
        /// </summary>
        /// <param name="e"></param>
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            Refresh();
        }
    }
}